<?php
/**
 * @Author:      ZH
 * @DateTime:  2017-07-13 13:38:30
 * @Description: 金蝶数据
 */
class JinDieFAccountInfo extends Eloquent
{
    protected $table = "FAccountInfo";

    /**
     * 多账套科目查询
     * UTF-8
     * GET
     * /api/exportAccount
     */
    //写入数据库
    public static function storeDataQuery($result){
        foreach($result as $val) {
            $JinDieFAccountInfo = JinDieFAccountInfo::where('FNumber',$val->FNumber)->orderBy('updated_at','desc')->first();
            if(!$JinDieFAccountInfo){
                $JinDieFAccountInfo = new JinDieFAccountInfo();
                $JinDieFAccountInfo->created_at = Common::currentTimeString();
            }
            $JinDieFAccountInfo->FPName = $val->FPName;
            $JinDieFAccountInfo->FPNumber = $val->FPNumber;
            $JinDieFAccountInfo->FName = $val->FName;
            $JinDieFAccountInfo->FNumber = $val->FNumber;
            $JinDieFAccountInfo->FGName = $val->FGName;
            $JinDieFAccountInfo->FClassName = $val->FClassName;
            try {
                $JinDieFAccountInfo->save();
            }catch(Exception $e){

            }
            foreach ($val->ItemList as $item){
                $FAccountHaveItems = JinDieFAccountHaveItems::where('account_id',$JinDieFAccountInfo->id)->where('FNumber',$item->FNumber)->orderBy('updated_at','desc')->first();
                if(!$FAccountHaveItems){
                    $FAccountHaveItems = new JinDieFAccountHaveItems();
                    $FAccountHaveItems->created_at = Common::currentTimeString();
                }
                $FAccountHaveItems->account_id = $JinDieFAccountInfo->id;
                $FAccountHaveItems->FNumber = $item->FNumber;
                $FAccountHaveItems->FName = $item->FName;
                $FAccountHaveItems->save();
            }
        }
    }
}